package good

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"homepage_srv/homepageclient"
)

type GetCommentsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetCommentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCommentsLogic {
	return &GetCommentsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 获取所有评论
func (l *GetCommentsLogic) GetComments(req *types.GetCommentsRequest) (resp *types.Response, err error) {
	commentList, err := l.svcCtx.HomepageGrpc.GetComments(l.ctx, &homepageclient.GetCommentsRequest{
		GoodId: req.GoodId,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(commentList), nil
}
